//
// Created by liushuai on 2021/2/16.
//

#include "addStrings.h"
// 123
//  45
// 1 6 8
<<<<<<< HEAD:cxx/algorithm/src/addStrings.cc
string addStrings(string num1, string num2){
    string min_str = num2;
    string max_str = num1;
    if(num1.size()<num2.size()){
        min_str = num1;
        max_str = num2;
    }
    string res;
    int forward = 0;
    int i = 0;
    for(;i<min_str.size();i++){
        int value = min_str[min_str.size()-1-i]+max_str[max_str.size()-1-i]-'0'-'0'+forward;
        char num = value%10+'0';
        forward = value/10;
        res+=num;
    }
    while(i<max_str.size()){
        int value = max_str[max_str.size()-1-i]+forward-'0';
        char num = value%10+'0';
        forward = value/10;
        res+=num;
        i++;
    }
    if(forward==1)
        res+=forward+'0';
    std::reverse(res.begin(),res.end());
    return res;
=======
string addStrings(string num1, string num2) {
  string min_str = num2;
  string max_str = num1;
  if (num1.size() < num2.size()) {
    min_str = num1;
    max_str = num2;
  }
  string res;
  int forward = 0;
  int i = 0;
  for (; i < min_str.size(); i++) {
    int value = min_str[min_str.size() - 1 - i] +
                max_str[max_str.size() - 1 - i] - '0' - '0' + forward;
    char num = value % 10 + '0';
    forward = value / 10;
    res += num;
  }
  while (i < max_str.size()) {
    int value = max_str[max_str.size() - 1 - i] + forward - '0';
    char num = value % 10 + '0';
    forward = value / 10;
    res += num;
    i++;
  }
  if (forward == 1) res += forward + '0';
  std::reverse(res.begin(), res.end());
  return res;
>>>>>>> dev:cxx/algorithm/common/src/addStrings.cc
}